/*
 * 文件名：LocalTemporaryCheckServiceImpl.java	 
 * 时     间：上午11:27:50
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.local.dao.mapers.LocalTemporaryCheckMapper;
import com.local.manager.dic.DicMananger;
import com.local.manager.locks.GlobalStaticEntity;
import com.local.model.LocalTemporaryCheck;
import com.local.model.LocalTemporaryCheckExample;
import com.local.service.face.LocalTemporaryCheckService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.entity.PageInfo;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.Tools;
import com.qianhai.common.utils.UUIDGenerateUtil;

/**
 * 类描述:这里是类描述
 * 
 * @ClassName: LocalTemporaryCheckServiceImpl
 * @author Administrator
 * @date 2015年10月6日 上午11:27:50
 */

@Service
public class LocalTemporaryCheckServiceImpl
		extends
		BaseServiceImpl<LocalTemporaryCheckExample, LocalTemporaryCheck, String>
		implements LocalTemporaryCheckService
{
	
	@Autowired
	private LocalTemporaryCheckMapper localTemporaryCheckMapper;
	
	@Override
	public String saveOrUpdateLocalTemporaryCheck(
			LocalTemporaryCheck localTemporaryCheck)
	{
		// TODO Auto-generated method stub
		try
		{
			
			if (!Tools.isEmpty(localTemporaryCheck.getRepeatType()))
			{
				if (localTemporaryCheck.getRepeatType().equals("2"))
				{
					// 弹框模式
					DicMananger.instance().setReptCarNoWhenCarIn(false);
				} else
				{
					// 覆盖模式
					DicMananger.instance().setReptCarNoWhenCarIn(true);
				}
			}
			
			List<LocalTemporaryCheck> list = localTemporaryCheckMapper
					.queryByPage(new PageInfo<LocalTemporaryCheck>());
			if ("1".equals(localTemporaryCheck.getType())
					|| Tools.isEmpty(localTemporaryCheck.getType()))
			{
				GlobalStaticEntity.instance().setLocalTemporaryCheckType(true);
			} else
			{
				GlobalStaticEntity.instance().setLocalTemporaryCheckType(false);
			}
			if (!Tools.isEmpty(list) && !list.isEmpty())
			{
				if (!Tools.isEmpty(localTemporaryCheck.getType()))
				{
					list.get(0)
							.setType(
									!Tools.isEmpty(localTemporaryCheck
											.getType()) ? localTemporaryCheck
											.getType() : "1");
				}
				if (!Tools.isEmpty(localTemporaryCheck.getRepeatType()))
				{
					list.get(0)
							.setRepeatType(
									!Tools.isEmpty(localTemporaryCheck
											.getRepeatType()) ? localTemporaryCheck
											.getRepeatType() : "1");
				}
				localTemporaryCheckMapper.updateByPrimaryKey(list.get(0));
				return "1";
			}
			
			LocalTemporaryCheck info = new LocalTemporaryCheck();
			info.setUuid(UUIDGenerateUtil.generate());
			info.setRepeatType(!Tools.isEmpty(localTemporaryCheck
					.getRepeatType()) ? localTemporaryCheck.getRepeatType()
					: "1");
			info.setType(!Tools.isEmpty(localTemporaryCheck.getType()) ? localTemporaryCheck
					.getType() : "1");
			localTemporaryCheckMapper.insertSelective(info);
			return "2";
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
	}
	
	@Override
	public BaseMapper<LocalTemporaryCheckExample, LocalTemporaryCheck, String> getMapper()
	{
		// TODO Auto-generated method stub
		return localTemporaryCheckMapper;
	}
	
	@Override
	public LocalTemporaryCheck queryLocalTemporaryCheck()
	{
		// TODO Auto-generated method stub
		LocalTemporaryCheck lc = localTemporaryCheckMapper
				.queryLocalTemporaryCheck();
		if (Tools.isEmpty(lc))
		{
			return null;
		} else
		{
			return lc;
		}
	}
	
	@Override
	public Boolean queryLocalTemporaryCheckStatus()
	{
		if (!Tools.isEmpty(GlobalStaticEntity.instance()
				.getLocalTemporaryCheckType()))
		{
			return GlobalStaticEntity.instance().getLocalTemporaryCheckType();
		} else
		{
			LocalTemporaryCheck lc = localTemporaryCheckMapper
					.queryLocalTemporaryCheck();
			if (Tools.isEmpty(lc))
			{
				return true;
			} else if ("2".equals(lc.getType()))
			{
				return false;
			} else
			{
				return true;
			}
		}
	}
}
